package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EcdBuy;
import com.ruoyi.system.service.IEcdBuyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 外购Controller
 * 
 * @author ruoyi
 * @date 2025-11-06
 */
@RestController
@RequestMapping("/system/buy")
public class EcdBuyController extends BaseController
{
    @Autowired
    private IEcdBuyService ecdBuyService;

    /**
     * 查询外购列表
     */
    @PreAuthorize("@ss.hasPermi('system:buy:list')")
    @GetMapping("/list")
    public TableDataInfo list(EcdBuy ecdBuy)
    {
        startPage();
        List<EcdBuy> list = ecdBuyService.selectEcdBuyList(ecdBuy);
        return getDataTable(list);
    }

    /**
     * 导出外购列表
     */
    @PreAuthorize("@ss.hasPermi('system:buy:export')")
    @Log(title = "外购", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EcdBuy ecdBuy)
    {
        List<EcdBuy> list = ecdBuyService.selectEcdBuyList(ecdBuy);
        ExcelUtil<EcdBuy> util = new ExcelUtil<EcdBuy>(EcdBuy.class);
        util.exportExcel(response, list, "外购数据");
    }

    /**
     * 获取外购详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:buy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ecdBuyService.selectEcdBuyById(id));
    }

    /**
     * 新增外购
     */
    @PreAuthorize("@ss.hasPermi('system:buy:add')")
    @Log(title = "外购", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EcdBuy ecdBuy)
    {
        return toAjax(ecdBuyService.insertEcdBuy(ecdBuy));
    }

    /**
     * 修改外购
     */
    @PreAuthorize("@ss.hasPermi('system:buy:edit')")
    @Log(title = "外购", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EcdBuy ecdBuy)
    {
        return toAjax(ecdBuyService.updateEcdBuy(ecdBuy));
    }

    /**
     * 删除外购
     */
    @PreAuthorize("@ss.hasPermi('system:buy:remove')")
    @Log(title = "外购", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ecdBuyService.deleteEcdBuyByIds(ids));
    }
}
